package com.aeroyun.macross.modular.countryside.controller;

import com.aeroyun.macross.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.aeroyun.macross.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.aeroyun.macross.modular.system.model.Village;
import com.aeroyun.macross.modular.countryside.service.IVillageService;

/**
 * 村庄管理控制器
 *
 * @author fengshuonan
 * @Date 2018-08-17 13:46:20
 */
@Controller
@RequestMapping("/village")
public class VillageController extends BaseController {

    private String PREFIX = "/countryside/village/";

    @Autowired
    private IVillageService villageService;

    /**
     * 跳转到村庄管理首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "village.html";
    }

    /**
     * 跳转到添加村庄管理
     */
    @RequestMapping("/village_add")
    public String villageAdd() {
        return PREFIX + "village_add.html";
    }

    /**
     * 跳转到修改村庄管理
     */
    @RequestMapping("/village_update/{villageId}")
    public String villageUpdate(@PathVariable Integer villageId, Model model) {
        Village village = villageService.selectById(villageId);
        model.addAttribute("item",village);
        LogObjectHolder.me().set(village);
        return PREFIX + "village_edit.html";
    }

    /**
     * 获取村庄管理列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return villageService.selectList(null);
    }

    /**
     * 新增村庄管理
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Village village) {
        villageService.insert(village);
        return SUCCESS_TIP;
    }

    /**
     * 删除村庄管理
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer villageId) {
        villageService.deleteById(villageId);
        return SUCCESS_TIP;
    }

    /**
     * 修改村庄管理
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Village village) {
        villageService.updateById(village);
        return SUCCESS_TIP;
    }

    /**
     * 村庄管理详情
     */
    @RequestMapping(value = "/detail/{villageId}")
    @ResponseBody
    public Object detail(@PathVariable("villageId") Integer villageId) {
        return villageService.selectById(villageId);
    }
}
